import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
import {BaseService} from '../../../shared/service/base.service';
import {ApiUrl} from '../../../config/api-url';
import {Consts} from '../../../config/consts';
import {RoleIdEnum} from '../../../enums/role-id.enum';

@Component({
  selector: 'app-site-customer-service-info',
  templateUrl: './site-customer-service-info.component.html',
  styleUrls: ['./site-customer-service-info.component.less']
})
export class SiteCustomerServiceInfoComponent implements OnInit {
  // 模态框显隐
  @Input()
  isVisibleBranInfo = false;

  @Input()
  store: any;

  customerServiceInfo = {
    serviceWeChatQr:'',
    serviceWeChatNumber:'',
    serviceMobilePhone:'',
    serviceFixedTelephone:'',
    id:'',
    userId:'',
    merchantStoreId:'',
  };
  roleIdEnum = {
    SUPER_ADMINISTRATOR: RoleIdEnum.SUPER_ADMINISTRATOR,
    AGENT: RoleIdEnum.AGENT,
    MERCHANT: RoleIdEnum.MERCHANT,
    SUB_ACCOUNT: RoleIdEnum.SUB_ACCOUNT,
  };
  userInfo: any;
  @Output()
  emit: EventEmitter<any> = new EventEmitter();
  serverFileUrl: any = Consts.imgUrl;
  constructor(private fb: FormBuilder, public baseService: BaseService) {
  }
  ngOnInit(): void {
    this.userInfo = JSON.parse(sessionStorage.getItem(Consts.USER_INFO));
  }
  ngOnChanges():void{
    if(this.isVisibleBranInfo && this.store != null){
      this.findMeiTuanPackageByStoreIdAndUserId();
    }
  }

  findMeiTuanPackageByStoreIdAndUserId(): void {
    let body = {
      userId: this.store.userId,
      merchantStoreId: this.store.merchantStoreId,
    }
    this.baseService.post(ApiUrl.CustomerServiceInfo + '/findCustomerServiceInfoByStoreId', body).subscribe(data => {
        if (data.status == 0) {
          this.customerServiceInfo = data.data;
        } else {
          this.baseService.layer.messageError(data.msg);
        }
      }
    );
  }
  handleCancel(){
    this.isVisibleBranInfo =false;
    this.emit.emit(this.isVisibleBranInfo);
  }
  editCustomerServiceInfo(){
    this.customerServiceInfo.userId = this.store.userId;
    this.customerServiceInfo.merchantStoreId = this.store.merchantStoreId;
    this.baseService.post(ApiUrl.CustomerServiceInfo + '/editCustomerServiceInfo', this.customerServiceInfo).subscribe(data => {
        if (data.status == 0) {
          this.baseService.layer.messageSuccess('修改成功');
          this.isVisibleBranInfo =false;
          this.emit.emit(this.isVisibleBranInfo);
        } else {
          this.baseService.layer.messageError(data.msg);
        }
      }
    );
  }
  handleOk(){

  }
}
